import java.util.*;

/**
 * @author wuwenfa
 */
public class Main {

    public static void main(String[] args) {
        one();

        two();

        three();

        four();

        five();
    }

    public static void one() {
        //编写一段程序，把"一站式门店运营服务平台"按单字符添加到HashSet中后，再删除"门店"两个字符，最后循环打印输出每一个字符。
        String str = "一站式门店运营服务平台";
        HashSet<Character> set = new HashSet<>();
        for (char a : str.toCharArray()) {
            set.add(a);
        }
        set.removeIf(a -> a == '门' || a == '店');
        for (char a : set) {
            System.out.println(a);
        }
    }

    public static void two() {
        //针对上面那段文字，删除并打印输出按自然排序的第一个字符和最后一个字符
        String str = "一站式门店运营服务平台";
        TreeSet<Character> set = new TreeSet<>();
        for (char a : str.toCharArray()) {
            set.add(a);
        }
        System.out.println("自然排序的第一个字符是：" + set.first());
        set.remove(set.first());
        System.out.println("自然排序的最后一个字符是：" + set.last());
        set.remove(set.last());
    }

    public static void three() {
        //    编写一段程序，统计这段文字"This class implements the <tt>Set</tt> interface, backed by a hash table(actually a <tt>HashMap</tt> instance).  It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time.  This class permits the <tt>null</tt> element."中不重复字符的数量。
        String str = "This class implements the <tt>Set</tt> interface, backed by a hash table(actually a <tt>HashMap</tt> instance).  It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time.  This class permits the <tt>null</tt> element.";
        HashSet<Character> set = new HashSet<>();
        for (char a : str.toCharArray()) {
            set.add(a);
        }
        System.out.println("不重复的字符数量是：" + set.size());
    }

    public static void four() {
        //编写一段程序，统计这段文字"This class offers constant time performance for the basic operations add remove contains and size"中不重复词语的数量，并按序列打印输出
        String str = "This class offers constant time performance for the basic operations add remove contains and size";
        Set<Character> set = new LinkedHashSet<>();
        for (char a : str.toCharArray()) {
            set.add(a);
        }
        System.out.println("不重复的字符数量是：" + set.size());
        for (char c : set) {
            System.out.println(c);
        }
    }

    public static void five() {
        //定义一个商品类（id,名称，分类，售价，创建时间），重写toString，可以输出json形式的商品信息，同时实现Comparable接口，能在TreeSet中按创建时间倒序排列。
        Good g1 = new Good(1, "苹果", "水果", 1.02d, 1603273929);
        Good g2 = new Good(2, "雪碧", "饮料", 3d, 1603273930);
        Good g3 = new Good(3, "苹果", "水果", 1.02d, 1603273929);
        Good g4 = new Good(3, "小蛋糕", "甜点", 5.23d, 1603273928);

        TreeSet<Good> set = new TreeSet<>();
        set.add(g1);
        set.add(g2);
        set.add(g3);
        set.add(g4);
        for (Good g : set) {
            System.out.println(g.toString());
        }
    }


}
